package com.fen.service.lmpl;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fen.common.Result;
import com.fen.dao.CompanyInfoMapper;
import com.fen.pojo.CompanyInfo;
import com.fen.service.CompanyInfoServict;
import com.fen.service.UserServict;
import com.fen.vo.requset.RequestCompanyInfoOV;
import com.fen.vo.response.ResponseCompanyName;
import org.apache.ibatis.annotations.One;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

/**
 * @Description: companyinfo表的service实现类
 * @Author: lijiafen
 * @Date:  2021/11/1
 * @Time: 17:35
 * @eamil: 2368044269@qq.com
 */
@Service
public class CompanyInfoServictImpl extends ServiceImpl<CompanyInfoMapper,CompanyInfo> implements CompanyInfoServict{
    @Autowired
    CompanyInfoMapper companyInfoMapper;

    /*添加单位*/
    @Override
    public boolean addCompanyInfo(RequestCompanyInfoOV requestCompanyInfoOV) {
       CompanyInfo companyInfo=new CompanyInfo();
        BeanUtils.copyProperties(requestCompanyInfoOV,companyInfo);
        companyInfo.setCreateTime(LocalDateTime.now());
        return save(companyInfo);
    }
    @Override
    public IPage<CompanyInfo> listCompanyinfo(RequestCompanyInfoOV requestCompanyInfoOV) {
        /*分页接口*/
        IPage<CompanyInfo> page=new Page<>(requestCompanyInfoOV.getDisplayStart(),requestCompanyInfoOV.getDisplayLength());
        /*构造一个查询器*/
        QueryWrapper<CompanyInfo> queryWrapper=new QueryWrapper<>();

        if (StringUtils.checkValNotNull(requestCompanyInfoOV.getCompanyName()))
        {
            /*用查询器使用like查询*/
            queryWrapper.like("company_name",requestCompanyInfoOV.getCompanyName());
        }
        if (StringUtils.checkValNotNull(requestCompanyInfoOV.getCompanyAddress()))
        {
            queryWrapper.like("company_address",requestCompanyInfoOV.getCompanyAddress());
        }
        if (StringUtils.checkValNotNull(requestCompanyInfoOV.getCompanyAddress()))
        {
            queryWrapper.like("company_linkman",requestCompanyInfoOV.getCompanyLinkman());
        }
       return page(page,queryWrapper);
    }

    @Override
    public List<ResponseCompanyName> selectname() {
        List<ResponseCompanyName> selectname = companyInfoMapper.selectname();
        return selectname;
    }
}
